package com.ehualu.esresult.utils;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Map;

public class DBConnection {

    private static final Logger LOG = LoggerFactory.getLogger(DBConnection.class);

    static Connection con = null;

    public static Connection getehldb() {

        LoadProperties loadProc = LoadProperties.getInstance();


        String driver = loadProc.getValues("dbdriver", "com.mysql.jdbc.Driver");
        String dburl = loadProc.getValues("dburl", "jdbc:mysql://192.168.22.18:3306/esresult");
        String dbusername = loadProc.getValues("dbusername", "root");
        String dbpassword = loadProc.getValues("dbpassword", "root");
        try {


            Class.forName(driver);
            con = DriverManager.getConnection(dburl, dbusername, dbpassword);

            LOG.info("ehl db Connection create!");

        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return con;
    }


    public static Connection getcon() {

        if (con == null) {

            getehldb();
        }
        return con;

    }

}
